package info.sean.util.common.network;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class IPUtil {

    public static List<String> getLocalInetAddress() {
        List<String> inetAddressList = new ArrayList();

        try {
            Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();

            while(enumeration.hasMoreElements()) {
                NetworkInterface networkInterface = (NetworkInterface)enumeration.nextElement();
                Enumeration<InetAddress> addrs = networkInterface.getInetAddresses();

                while(addrs.hasMoreElements()) {
                    inetAddressList.add(((InetAddress)addrs.nextElement()).getHostAddress());
                }
            }

            return inetAddressList;
        } catch (SocketException var4) {
            throw new RuntimeException("get local inet address fail", var4);
        }
    }

    public static String localhostAddress() {
        try {
            InetAddress addr = InetAddress.getLocalHost();
            return addr.getHostAddress();
        } catch (Throwable var1) {
            return "";
        }
    }
}
